<template>
	<view class="plr-20">
		<view class="u-cb-white-bg padding-30 mt-20 u-flex u-flex-between u-flex-items-center">
			<view class="u-flex u-flex-items-center">
				<u-avatar
					:text="uinfo.FAname"
					fontSize="24"
					size="60"
					randomBgColor>
				</u-avatar>
				<view class="ml-20 lh-40">
					<view class="">{{uinfo.FName}}</view>
					<view class="">{{uinfo.FNumber}}</view>
				</view>
			</view>
			<view class="">
				<u-button text="退出登录" type="error" @click="loginOut"/>
			</view>
		</view>
		<view class="u-cb-white-bg mt-20">
			<u-cell-group :border="false" v-if="uinfo.FMemberID!==0">
				<u-cell title="会员中心" :isLink="true" @click="$u.route({url:'/pages/home/index-member',type:'redirectTo'})"/>
			</u-cell-group>
			<u-cell-group :border="false">
				<u-cell title="修改登录密码" :border="false" :isLink="true" @click="$u.route('/pages/login/setpw',{type:1})"/>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex'
	export default{
		data(){
			return{
				uinfo:{}
			}
		},
		onLoad() {
			this.getUInfo()
		},
		methods:{
			...mapMutations(['logout']),
			loginOut(){
				let that = this
				const accountInfo = uni.getAccountInfoSync();
				uni.login({
					provider: 'weixin',
					success: function (loginRes){
						that.$reqGet('/OnUserlogout', {
							type: 1,
							appid: accountInfo.miniProgram.appId,
							code: loginRes.code
						}).then(res=>{
							that.logout()
							uni.$u.route('/pages/login/index')
						})
					}
				})
				// this.logout()
				// uni.$u.route('/pages/login/index')
			},
			getUInfo(){
				this.$reqGet('GetUserInfo',{
					type: 1
				}).then(res=>{
					this.uinfo = res.Data
					this.uinfo.FMemberID = uni.getStorageSync('userInfo').FMemberID
					this.uinfo.FAname = res.Data.FName.substring(0, 1)
				})
			}
		}
	}
</script>

<style>
</style>